package com.wingsfrog.puzzle.modules.dao;

import com.wingsfrog.puzzle.modules.entity.Puzzles;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;

public interface PuzzlesDao extends CrudRepository<Puzzles,Integer>{
    @Query("select p from Puzzles p where p.hash=?1 and p.blank=?2")
    public Puzzles findByHash(Long hash, int start);

    @Query(value = "SELECT * FROM puzzles" +
            " WHERE id >= (SELECT FLOOR(MAX(id) * RAND()) FROM puzzles WHERE step=?1) and step=?1 " +
            " ORDER BY id" +
            " LIMIT 1", nativeQuery = true)
    public Puzzles findByHardness(int hardness);
}
